<template>
  <!-- 歌单详情顶部 -->
  <div class="itemMusicTop">
    <!-- 背景图 -->
    <img 
      :src="playlist.coverImgUrl" 
      alt="歌单封面背景" 
      class="bgimg"
      @error="handleImageError"
    >
    
    <!-- 导航栏 -->
    <div class="navigation">
      <div class="itemLeft">
        <button class="backBtn" @click="$router.go(-1)" aria-label="返回">
          <svg class="icon" aria-hidden="true">
            <use xlink:href="#icon-zuojiantou"></use>
          </svg>
        </button>
        <span class="typeLabel">歌单</span>
      </div>
      <div class="itemRight">
        <button class="actionBtn" aria-label="搜索">
          <svg class="icon">
            <use xlink:href="#icon-sousuo"></use>
          </svg>
        </button>
        <button class="actionBtn" aria-label="更多操作">
          <svg class="icon">
            <use xlink:href="#icon-31liebiao"></use>
          </svg>
        </button>
      </div>
    </div>

    <!-- 主要内容区 -->
    <div v-if="!isLoading" class="itemTopContent">
      <!-- 封面区 -->
      <div class="coverSection">
        <div class="contentLeft">
          <img 
            :src="playlist.coverImgUrl" 
            alt="歌单封面"
            class="coverImg"
            @error="handleImageError"
          >
          <div class="playCount">
            <svg class="icon">
              <use xlink:href="#icon-gl-play-copy"></use>
            </svg>
            <span>{{ formatPlayCount(playlist.playCount) }}</span>
          </div>
        </div>

        <!-- 信息区 -->
        <div class="infoSection">
          <h1 class="title">{{ playlist.name }}</h1>
          <div class="creatorInfo">
            <img 
              :src="creatorBackground" 
              alt="创建者头像"
              class="creatorAvatar"
            >
            <span class="creatorName">{{ creatorName }}</span>
            <svg class="arrowIcon">
              <use xlink:href="#icon-youjiantou"></use>
            </svg>
          </div>
          <div class="description">
            <p class="descText">{{ truncatedDescription }}</p>
            <svg class="arrowIcon">
              <use xlink:href="#icon-youjiantou"></use>
            </svg>
          </div>
        </div>
      </div>
    </div>
    <div v-else class="loadingState">
      <!-- 骨架屏加载状态 -->
    </div>

    <!-- 统计信息栏 -->
    <div class="statsBar">
      <div class="statItem" v-for="stat in statistics" :key="stat.label">
        <svg class="statIcon">
          <use :xlink:href="stat.icon"></use>
        </svg>
        <span class="statValue">{{ stat.value }}</span>
      </div>
    </div>
  </div>
</template>

<script>
import { computed, ref } from 'vue'

export default {
  props: {
    playlist: {
      type: Object,
      required: true,
      validator: (value) => {
        return [
          'coverImgUrl', 
          'playCount', 
          'name', 
          'creator',
          'description',
          'commentCount',
          'shareCount'
        ].every(prop => prop in value)
      }
    }
  },

  setup(props) {
    // 加载状态
    const isLoading = ref(false)
    
    // 图片加载失败处理
    const handleImageError = (e) => {
      e.target.src = '/default-cover.jpg'
    }

    // 创建者信息处理
    const creatorInfo = computed(() => {
      return props.playlist.creator || {
        backgroundUrl: '/default-avatar.jpg',
        nickname: '未知用户'
      }
    })

    // 数据处理
    const formatPlayCount = (num) => {
      const number = Number(num) || 0
      if (number >= 1e8) return `${(number / 1e8).toFixed(1)}亿`
      if (number >= 1e4) return `${(number / 1e4).toFixed(1)}万`
      return number.toLocaleString()
    }

    // 统计信息
    const statistics = computed(() => [
      { icon: '#icon-iconfontzhizuobiaozhun023110', value: props.playlist.commentCount },
      { icon: '#icon-fenxiang', value: props.playlist.shareCount },
      { icon: '#icon-iconfontzhizuobiaozhun023146', value: '下载' },
      { icon: '#icon-show_duoxuan', value: '多选' }
    ])

    return {
      isLoading,
      handleImageError,
      creatorInfo,
      formatPlayCount,
      statistics
    }
  }
}
</script>
<style lang="less" scoped>
.itemMusicTop {
  width: 100%;
  height: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  // padding: .2rem;
  position: relative;
  .itemLeft,
  .itemRight {
    width: 25%;
    height: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 0 0.2rem;
    span {
      font-size: 0.4rem;
      color: #fff;
    }
    .icon {
      fill: #fff; //填充颜色
    }
  }
  .bgimg {
    width: 100%;
    height: 11rem;
    position: absolute;
    z-index: -1;
    filter: blur(30px);
  }
}
.itemTopContent {
  width: 100%;
  height: 3rem;
  padding: 0.2rem;
  margin-top: 0.4rem;
  display: flex;
  justify-content: space-between;
  .contentLeft {
    width: 36%;
    height: 2.6rem;
    position: relative;

    img {
      width: 2.6rem;
      height: 2.6rem;
      border-radius: 0.2rem;
      position: absolute;
      z-index: -1;
    }
    .palyCount {
      position: absolute;
      right: 0.1rem;
      margin-top: 0.1rem;
      .icon {
        width: 0.26rem;
        height: 0.26rem;
        margin-top: -0.02rem;
        vertical-align: middle;
      }
      span {
        font-size: 0.26rem;
        color: #fff;
      }
    }
  }
  .contentRight {
    width: 60%;
    height: 2.6rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    .rightP_one {
      font-size: 0.3rem;
      font-weight: 900;
      color: #fff;
      font-family: "微软雅黑";
    }
    .right_img {
      width: 100%;
      height: 0.6rem;
      line-height: 0.6rem;
      color: #ccc;
      img {
        width: 0.6rem;
        height: 0.6rem;
        border-radius: 50%;
        vertical-align: middle;
      }
      span {
        margin-left: 0.1rem;
      }
      .icon {
        width: 0.26rem;
        height: 0.26rem;
        margin-top: -0.08rem;
        vertical-align: middle;
      }
    }
    .rightP_two {
      width: 100%;
      height: 0.6rem;
      display: flex;
      align-items: center;
      justify-content: space-between;
      span {
        display: inline-block;
        width: 95%;
        height: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        font-size: 0.24rem;
        color: #ccc;
      }
      .icon {
        width: 0.24rem;
        height: 0.24rem;
      }
    }
  }
}
.itemTopFooter{
  width: 100%;
  height: 1.4rem;
  display: flex;
  justify-content: space-around;
  margin-top: .2rem;
  .footerItem{
    display: flex;
    flex-direction: column;
    align-items: center;
    color: #fff;
    .icon{
      fill: #fff;
    }
    span{
      margin-top: .1rem;
    }
  }

}
</style>